﻿package com.tudou.ad.view.base
{
    import com.tudou.ad.components.*;
    import com.tudou.ad.components.events.*;
    import com.tudou.ad.events.*;
    import com.tudou.ad.interfaces.*;
    import com.tudou.track.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.events.*;

    public class AdItemViewBase extends EventDispatcher implements IAdItemView
    {
        protected var _mainWidth:Number = 0;
        protected var frontAdSprite:TudouAdSprite;
        protected var _adThrowInfo:IAdThrowInfo;
        protected var _hasFront:Boolean = false;
        private var _bgHeight:Number = 0;
        protected var bgAdSprite:TudouAdSprite;
        protected var _isVideo:Boolean;
        private var _bgWidth:Number = 0;
        protected var _adItemInfo:IAdItemInfo;
        protected var frontStuff:DisplayObject;
        protected var _isFullscreen:Boolean = false;
        protected var _frontAdSpriteAlpha:Number = 1;
        protected var _hasBg:Boolean = false;
        protected var _mainTop:Number = 0;
        protected var bgStuff:DisplayObject;
        protected var _etime:Number = 0;
        protected var _isShowing:Boolean;
        protected var _countDownTime:int = 0;
        protected var _isExpand:Boolean = false;
        protected var _mainHeight:Number = 0;
        protected var viewBox:Sprite;
        protected var _isInited:Boolean = false;
        protected var _isSkip:Boolean;
        protected var _tracker:IAdTracker;

        public function AdItemViewBase()
        {
            return;
        }// end function

        public function set bgWidth(param1:Number) : void
        {
            _bgWidth = param1;
            return;
        }// end function

        public function hideAd() : void
        {
            adDisplay.visible = false;
            return;
        }// end function

        public function showAd() : void
        {
            adDisplay.visible = true;
            return;
        }// end function

        protected function _adShowSkip() : void
        {
            sendTrack(NodeLog.AD_SKIP);
            return;
        }// end function

        protected function swfCompleteHlr(event:TudouAdSpriteEvent) : void
        {
            adShowComplete();
            return;
        }// end function

        public function getEvents() : Array
        {
            return [AdItemViewEvent.SHOW_START, AdItemViewEvent.SHOW_END, AdItemViewEvent.SHOW_NEAR_END];
        }// end function

        protected function adShowComplete() : void
        {
            return;
        }// end function

        public function set mainWidth(param1:Number) : void
        {
            _mainWidth = param1;
            return;
        }// end function

        public function get adDisplay() : DisplayObject
        {
            return viewBox;
        }// end function

        public function startAd() : void
        {
            return;
        }// end function

        protected function adFloatClick() : void
        {
            openURL(adItemInfo.fLink);
            sendTrack(NodeLog.AD_FLOAT_CLICK);
            return;
        }// end function

        protected function adClick(param1:String = null) : void
        {
            openURL(adItemInfo.link);
            _adClick(param1);
            return;
        }// end function

        protected function _adShowComplete() : void
        {
            sendTrack(NodeLog.AD_SHOW_COMPLETE);
            return;
        }// end function

        protected function get isShowing() : Boolean
        {
            return _isShowing;
        }// end function

        public function get mainHeight() : Number
        {
            return _mainHeight;
        }// end function

        public function initToShow() : void
        {
            return;
        }// end function

        protected function initToShowCommon() : Boolean
        {
            if (!adItemInfo || _isInited)
            {
                return false;
            }
            _isInited = true;
            if (viewBox == null)
            {
                viewBox = new Sprite();
            }
            viewBox.visible = false;
            return true;
        }// end function

        protected function _debug(param1:String) : void
        {
            if (!adItemInfo)
            {
                trace("ad view: null " + param1);
                return;
            }
            trace("ad view: " + adItemInfo.type + ", " + param1);
            return;
        }// end function

        public function set adItemInfo(param1:IAdItemInfo) : void
        {
            _adItemInfo = param1;
            return;
        }// end function

        protected function clearAdCommon() : Boolean
        {
            if (!isShowing)
            {
                if (_isInited)
                {
                    clearComps();
                }
                return false;
            }
            isShowing = false;
            return true;
        }// end function

        public function addToShowBgStuff() : void
        {
            if (bgAdSprite && bgStuff)
            {
                bgAdSprite.addAdDisplay(bgStuff);
            }
            return;
        }// end function

        public function clearAd() : void
        {
            return;
        }// end function

        public function addToShowStuff() : void
        {
            if (frontAdSprite && frontStuff)
            {
                frontAdSprite.addAdDisplay(frontStuff);
            }
            return;
        }// end function

        protected function set hasFront(param1:Boolean) : void
        {
            _hasFront = param1;
            return;
        }// end function

        protected function startAdCommon() : Boolean
        {
            if (!adItemInfo)
            {
                _debug("!!! must check: startAdCommon !adItemInfo, adShowEnd");
                adShowEnd();
                return false;
            }
            if (isShowing)
            {
                return false;
            }
            isShowing = true;
            return true;
        }// end function

        public function get isVideo() : Boolean
        {
            return _isVideo;
        }// end function

        public function goTransform(param1:uint, param2:uint, param3:Boolean) : void
        {
            return;
        }// end function

        protected function set isShowing(param1:Boolean) : void
        {
            _isShowing = param1;
            return;
        }// end function

        public function set tracker(param1:IAdTracker) : void
        {
            _tracker = param1;
            return;
        }// end function

        protected function initFrontStuff() : void
        {
            frontAdSprite = new TudouAdSprite(mainWidth, mainHeight, 0, _frontAdSpriteAlpha);
            viewBox.addChild(frontAdSprite);
            frontAdSprite.addEventListener(TudouAdSpriteEvent.COMPLETE, swfCompleteHlr);
            frontAdSprite.addEventListener(TudouAdSpriteEvent.CLICK, frontStuffClickHlr);
            return;
        }// end function

        protected function get hasBg() : Boolean
        {
            return _hasBg;
        }// end function

        public function get bgWidth() : Number
        {
            return _bgWidth;
        }// end function

        protected function adShowStart() : void
        {
            dispatchEvent(new AdItemViewEvent(AdItemViewEvent.SHOW_START));
            sendTrack(NodeLog.AD_SHOW_START);
            return;
        }// end function

        public function set countDownTime(param1:int) : void
        {
            _countDownTime = param1;
            return;
        }// end function

        public function set mainHeight(param1:Number) : void
        {
            _mainHeight = param1;
            return;
        }// end function

        protected function clearFrontStuff() : void
        {
            if (frontAdSprite)
            {
                frontAdSprite.removeEventListener(TudouAdSpriteEvent.COMPLETE, swfCompleteHlr);
                frontAdSprite.removeEventListener(TudouAdSpriteEvent.CLICK, frontStuffClickHlr);
                frontAdSprite.removeAdDisplay();
                viewBox.removeChild(frontAdSprite);
            }
            frontAdSprite = null;
            return;
        }// end function

        public function set etime(param1:Number) : void
        {
            _etime = param1;
            return;
        }// end function

        public function set isSkip(param1:Boolean) : void
        {
            _isSkip = param1;
            return;
        }// end function

        public function get mainWidth() : Number
        {
            return _mainWidth;
        }// end function

        public function set bgHeight(param1:Number) : void
        {
            _bgHeight = param1;
            return;
        }// end function

        public function set adThrowInfo(param1:IAdThrowInfo) : void
        {
            _adThrowInfo = param1;
            return;
        }// end function

        protected function sendTrack(param1:String, param2:Array = null) : void
        {
            if (!_tracker)
            {
                return;
            }
            _tracker.adSend(adItemInfo, adThrowInfo, param1, param2);
            return;
        }// end function

        public function get adItemInfo() : IAdItemInfo
        {
            return _adItemInfo;
        }// end function

        protected function frontStuffClickHlr(event:TudouAdSpriteEvent) : void
        {
            adClick(event.data.toString());
            return;
        }// end function

        public function get etime() : Number
        {
            return _etime;
        }// end function

        protected function get hasFront() : Boolean
        {
            return _hasFront;
        }// end function

        public function set mainTop(param1:Number) : void
        {
            _mainTop = param1;
            return;
        }// end function

        protected function adShowNearEnd() : void
        {
            dispatchEvent(new AdItemViewEvent(AdItemViewEvent.SHOW_NEAR_END));
            return;
        }// end function

        public function setStuff(param1:DisplayObject) : void
        {
            frontStuff = param1;
            return;
        }// end function

        protected function clearCompsCommon() : void
        {
            if (viewBox)
            {
                while (viewBox.numChildren > 0)
                {
                    
                    viewBox.removeChildAt(0);
                }
            }
            viewBox = null;
            frontStuff = null;
            bgStuff = null;
            _isInited = false;
            return;
        }// end function

        public function get isSkip() : Boolean
        {
            return _isSkip;
        }// end function

        public function set isExpand(param1:Boolean) : void
        {
            _isExpand = param1;
            return;
        }// end function

        public function get bgHeight() : Number
        {
            return _bgHeight;
        }// end function

        public function get mainTop() : Number
        {
            return _mainTop;
        }// end function

        public function get adThrowInfo() : IAdThrowInfo
        {
            return _adThrowInfo;
        }// end function

        public function set isVideo(param1:Boolean) : void
        {
            _isVideo = param1;
            return;
        }// end function

        protected function _adClick(param1:String = null) : void
        {
            sendTrack(NodeLog.AD_CLICK, [param1]);
            return;
        }// end function

        protected function _adShowUserSkip() : void
        {
            sendTrack(NodeLog.AD_USER_SKIP);
            return;
        }// end function

        public function setBgStuff(param1:DisplayObject) : void
        {
            bgStuff = param1;
            return;
        }// end function

        protected function clearComps() : void
        {
            return;
        }// end function

        protected function adShowEnd() : void
        {
            dispatchEvent(new AdItemViewEvent(AdItemViewEvent.SHOW_END));
            return;
        }// end function

        protected function set hasBg(param1:Boolean) : void
        {
            _hasBg = param1;
            return;
        }// end function

    }
}
